package com.it2297.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;

import com.it2297.controller.CompanyController;
import com.it2297.main.CompanyApp;

import javax.swing.SwingConstants;
import java.awt.SystemColor;

public class CompanyViewDetails extends JFrame {

	private JMenuBar menuBar;
	private JMenu menuHome;
	private JMenu menuExit;
	private JMenu menuJobAd;
	private JMenuItem menuRemoveJob;
	private JMenuItem menuCreateJob;
	private JMenuItem menuViewAllJobsByCompany;
	private JMenu menuApplicants;
	private JMenuItem menuViewApplicants;
	private JSeparator separator;
	private Component horizontalGlue;
	private Component horizontalStrut;
	private JLabel lblWelcome;
	private JMenuItem menuLogout;
	private JMenuItem menuhomescreen;
	private JMenu mnProfile;
    private JMenuItem mntmUpdateCompany;
	
	private JPanel contentPane;
	private JTextField tb_name;  
    private JTextField tb_email;
    private JTextField tb_phone;
    final CompanyController cct= new CompanyController(this);   
    private JButton btnview;
    private JTextArea tb_address;
    private JTextArea tb_desc;
    private JButton btnRefresh;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CompanyViewDetails frame = new CompanyViewDetails();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
*/
	/**
	 * Create the frame.
	 */
	public CompanyViewDetails() {
		 String currentWorkingDirectory = System.getProperty("user.dir");
		 //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		 setBounds(100, 100, 740, 560);
		 contentPane = new JPanel();
		 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		 setContentPane(contentPane);
		 contentPane.setLayout(null);

		 JLabel lblCompanyRegistration = new JLabel("Company Details");			 
        lblCompanyRegistration.setFont(new Font("Times New Roman", Font.BOLD, 35));
        lblCompanyRegistration.setBounds(10, 26, 704, 55);
        getContentPane().add(lblCompanyRegistration);
       
        JLabel lblCompanyName = new JLabel("Company Name:");
        lblCompanyName.setFont(new Font("Tahoma", Font.BOLD, 14));
        lblCompanyName.setBounds(10, 79, 188, 24);
        getContentPane().add(lblCompanyName);

        JLabel lblNewLabel = new JLabel("Company Email:");
        lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
        lblNewLabel.setBounds(10, 415, 188, 24);
        getContentPane().add(lblNewLabel);
        
        JLabel lblNewLabel_1 = new JLabel("Company Address:");
        lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
        lblNewLabel_1.setBounds(10, 114, 188, 24);
        getContentPane().add(lblNewLabel_1);
       
        JLabel lblNewLabel_2 = new JLabel("Company Phone Number:");
        lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 14));
        lblNewLabel_2.setBounds(10, 380, 188, 24);
        getContentPane().add(lblNewLabel_2);
        
        JLabel lblNewLabel_3 = new JLabel("Company Description:");
        lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 14));
        lblNewLabel_3.setBounds(10, 246, 188, 24);
        getContentPane().add(lblNewLabel_3);
        
        tb_name = new JTextField();
        tb_name.setText(CompanyApp.getCurrentUser().getCompanyName());
        tb_name.setEditable(false);
        tb_name.setBounds(128, 80, 321, 26);
        getContentPane().add(tb_name);
        tb_name.setColumns(10);
  
        tb_email = new JTextField();
        tb_email.setText(CompanyApp.getCurrentUser().getEmail());
        tb_email.setEditable(false);
        tb_email.setBounds(126, 416, 262, 26);
        getContentPane().add(tb_email);
        tb_email.setColumns(10);	         

        tb_phone = new JTextField();
        tb_phone.setText(Integer.toString(CompanyApp.getCurrentUser().getPhone()));
        tb_phone.setEditable(false);
        tb_phone.setBounds(193, 381, 145, 26);
        getContentPane().add(tb_phone);
        tb_phone.setColumns(10);

        tb_address = new JTextArea();
        tb_address.setBackground(SystemColor.control);
        tb_address.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
        tb_address.setText(CompanyApp.getCurrentUser().getAddress());
        tb_address.setBounds(10, 135, 282, 100);
        contentPane.add(tb_address);
        
        tb_desc = new JTextArea();
        tb_desc.setBackground(SystemColor.control);
        tb_desc.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
        tb_desc.setText(CompanyApp.getCurrentUser().getDescription());
        tb_desc.setBounds(10, 269, 439, 100);
        contentPane.add(tb_desc);
        
        
        
        
        menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 724, 24);
		contentPane.add(menuBar);
		
		menuHome = new JMenu("Home");
		menuBar.add(menuHome);
		menuhomescreen=new JMenuItem("Home Screen");
		menuhomescreen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CompanyHomePage chp=new CompanyHomePage();
				chp.setLocationRelativeTo(null);
				chp.setVisible(true);
				chp.setTimer("start");
				chp.setTitle("Company - Home Screen");
				closeWindow();
			}
		});
		menuHome.add(menuhomescreen);
		
		menuJobAd=new JMenu("Job Advertisement");
		menuBar.add(menuJobAd);
		menuCreateJob=new JMenuItem("Create Job Advertisement");
		menuCreateJob.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JobCreateJob jcj=new JobCreateJob();
				jcj.setLocationRelativeTo(null);
				jcj.setVisible(true);
				jcj.setTitle("Company - Create Job Advertisement ");
				closeWindow();
			}
		});
		menuJobAd.add(menuCreateJob);
		
		JSeparator separator_1 = new JSeparator();
		menuJobAd.add(separator_1);
		menuRemoveJob=new JMenuItem("Remove Job Advertisement");
		menuRemoveJob.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JobRemoveJob jrj=new JobRemoveJob();
				jrj.setLocationRelativeTo(null);
				jrj.setVisible(true);
				jrj.setTitle("Company - Remove Job Advertisement ");
				closeWindow();
			}
		});
		menuViewAllJobsByCompany=new JMenuItem("View All Jobs By Company");
		menuViewAllJobsByCompany.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CompanyViewAllJobsByCompany cvajbc=new CompanyViewAllJobsByCompany();
				cvajbc.setLocationRelativeTo(null);
				cvajbc.setVisible(true);
				cvajbc.setTitle("Company - View All Jobs By Company ");
				closeWindow();
			}
		});
		menuJobAd.add(menuViewAllJobsByCompany);
		
		JSeparator separator_2 = new JSeparator();
		menuJobAd.add(separator_2);
		menuJobAd.add(menuRemoveJob);
		
		horizontalGlue = Box.createHorizontalGlue();
		menuBar.add(horizontalGlue);
		
		
		
		lblWelcome = new JLabel();
		lblWelcome.setForeground(new Color(0, 0, 128));
		if (CompanyApp.isUserLogin())
		{
			lblWelcome.setText("Welcome, " + CompanyApp.getCurrentUser().getCompanyName() + ".");
		}
		else
		{
			lblWelcome.setText("Welcome, Guest! Please Login.");
		}
		menuBar.add(lblWelcome);
		
		horizontalStrut = Box.createHorizontalStrut(20);
		menuBar.add(horizontalStrut);
		
		mnProfile = new JMenu("Profile");
		menuBar.add(mnProfile);
		
		mntmUpdateCompany = new JMenuItem("Update Company");
		mntmUpdateCompany.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CompanyUpdateCompany cuc = new CompanyUpdateCompany();
				cuc.setLocationRelativeTo(null);
				cuc.setVisible(true);
				cuc.setTitle("Company - Update Company Details");
				closeWindow();
			}
		});
		
		JMenuItem mntmViewCompany = new JMenuItem("View Company");
		mntmViewCompany.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CompanyViewDetails cvd= new CompanyViewDetails();
				cvd.setLocationRelativeTo(null);
				cvd.setVisible(true);
				cvd.setTitle("Company - View Company Details");
				closeWindow();
			}
		});
		mnProfile.add(mntmViewCompany);
		
		JSeparator separator_3 = new JSeparator();
		mnProfile.add(separator_3);
		mnProfile.add(mntmUpdateCompany);
		
		
		menuExit = new JMenu("Exit");
		menuBar.add(menuExit);
		menuLogout=new JMenuItem("Logout");
		menuLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CompanyApp.logoutUser();
				
				CompanyLogin loginUI = new CompanyLogin();
				loginUI.setLocationRelativeTo(null);
				loginUI.setVisible(true);
				closeWindow();
			}
		});
		menuExit.add(menuLogout);
		
		JLabel img = new JLabel("");
		img.setHorizontalAlignment(SwingConstants.CENTER);
		img.setIcon(new ImageIcon(currentWorkingDirectory + "/img/Job/company.jpg"));
		img.setBounds(459, 23, 265, 499);
		contentPane.add(img);
		
		/*btnRefresh = new JButton("Refresh");
		btnRefresh.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				cct.refresh();
			}
		});
		btnRefresh.setBounds(326, 135, 89, 23);
		contentPane.add(btnRefresh);
	*/
		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(0, 23, 724, 499);
		contentPane.add(panel);
		
		
		
		
	}
	
	public String getName(){
		return tb_name.getText();
	}
	
	public void closeWindow()
	{
		this.dispose();
	}
}
